﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebFrontEnd
{
    public partial class Default : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = GetCurrentUser();
            userNameLabel.InnerText = user.FirstName;

            var nextEvent = BL.GetUsersEvents(user).
                OrderBy(ev => ev.DateOfEvent).Where(ev => ev.DateOfEvent > DateTime.Now).FirstOrDefault();
            if (nextEvent == null)
            {
                nextEvDiv.Visible = false;
                emptyEventLabel.Visible = true;
            }
            else
            {
                emptyEventLabel.Visible = false;
                eventMainLink.HRef = "Event.aspx?eventID=" + nextEvent.ID.ToString();
                eventMainLink.InnerText = nextEvent.Name;
                eventNameSpan.InnerText = nextEvent.Name;
                startCount.Attributes["data-date"] = nextEvent.DateOfEvent.ToString("MMMM d, yyyy HH:mm:ss");
            }
        }
    }
}